from flask import Blueprint, request, jsonify

message_bp = Blueprint('message', __name__, url_prefix='/message')

messages = []


@message_bp.route('/publish', methods=['POST'])
def publish_message():
    message = request.json
    if not all(message.get(key) for key in ['from', 'to', 'message']):
        return jsonify(False), 400
    messages.append(message)
    return jsonify(True)


@message_bp.route('/getMessageInfo', methods=['GET'])
def get_message_info():
    return jsonify(messages)
